import { ref, Ref } from "vue";
import { useGet } from "./use-http";

interface UseCaptchaReturn {
  picPath: Ref<string>;
  picId: Ref<string>;
  getCode: () => void
}

export function useCaptcha(): UseCaptchaReturn {
  const picPath = ref("");
  const picId = ref("");

  function getCode() {
    useGet({
      url: "/v1/base/captcha",
      params: {},
      success: (data) => {
        picPath.value = data.picPath;
        picId.value = data.captchaId;
      },
    });
  }

  getCode();

  return {
    picPath,
    picId,
    getCode
  };
}
